package com.cc8w.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileUploadException;
import org.dom4j.DocumentException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;

import com.cc8w.util.RequestData;

/**
 * 控制器基类
 * @author Administrator
 *
 */
@Controller
public class BaseController {
	protected HttpServletRequest request=null;
	protected HttpServletResponse response=null;
	protected Model model=null;
	
	@ModelAttribute("attributeInit")
	public String init(HttpServletRequest request, HttpServletResponse response,Model model) throws IOException, DocumentException, FileUploadException {
		System.out.println("每次请求都执行BaseController");
		this.setRequest(request);
		this.setResponse(response);
		
		//有处理请求参数的方法
		//RequestData rd = new RequestData(request);
		
		
    	//项目名称
    	String path = request.getContextPath();
    	//项目网址加项目名称
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        model.addAttribute("APP_PATH", path);
        model.addAttribute("BASE_PATH", basePath);
        
		this.setModel(model);
		return "";
	}
	
	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
	}

}
